//
//  MainPageNearbyCell.m
//  RocketProject
//
//  Created by chen jiedan on 13-6-24.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "MainPageNearbyCell.h"
#import "UIColor-Expanded.h"
#import "CommonDefines.h"
#import <QuartzCore/QuartzCore.h>

#define kBGImageFile             @"image_discount_cell_bg.png"
#define kLineImageFile           @"image_line_type3.png"

@implementation MainPageNearbyCell
@synthesize delegate = _delegate;
@synthesize isShopMode = _isShopMode;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.contentView.backgroundColor = [UIColor colorWithHex:0xffededed];
        [self setUpView];
    }
    return self;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier withShopMode:(BOOL)shopMode
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _isShopMode = shopMode;
        self.contentView.backgroundColor = [UIColor colorWithHex:0xffededed];
        if (_isShopMode) {
            [self setUpShopModeView];
        }
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void) setUpView
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UILabel *t = [[UILabel alloc] initWithFrame:CGRectMake(14, 15, 60, 18)];
    t.font = [UIFont fontWithName:kFontNameHelvetica size:18];
    t.textColor = [UIColor colorWithHex:0xff505050];
    t.text = @"附近";
    [t setBackgroundColor:[UIColor clearColor]];
    [self addSubview:t];
    [t release];
    
    for (int i = 0; i < 6; i++) {
        int row = i/3;
        int number = i%3;
        UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"search_tu00%d",i+1]];
        UIButton *t = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 80, 60)];
        t.center = CGPointMake(54+107*number, 75+row*107);
        [t setImage:img forState:UIControlStateNormal];
        [t setImage:img forState:UIControlStateHighlighted];
        t.tag = i;
        [t addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [t setBackgroundColor:[UIColor clearColor]];
        [self.contentView addSubview:t];
        [t release];
        
        UILabel *tLabel = [[UILabel alloc] initWithFrame:CGRectMake(t.frame.origin.x-10, t.frame.origin.y + t.frame.size.height, t.frame.size.width+20, 14)];
        [self.contentView addSubview:tLabel];
        if (i == 0)         tLabel.text = @"美食";
        else if (i == 1)    tLabel.text = @"住宿";
        else if (i == 2)    tLabel.text = @"行程";
        else if (i == 3)    tLabel.text = @"旅游";
        else if (i == 4)    tLabel.text = @"娱乐";
        else if (i == 5)    tLabel.text = @"更多";
//        else if (i == 6)    tLabel.text = @"商助";
//        else if (i == 7)    tLabel.text = @"积分商城";
        tLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
        tLabel.textColor = [UIColor colorWithHex:0xff786e67];
        [tLabel setBackgroundColor:[UIColor clearColor]];
        [tLabel setTextAlignment:NSTextAlignmentCenter];
        [tLabel release];
    }
    UIImageView *lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 134, 320, 1)];
    lineImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
    [lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self.contentView addSubview:lineImageView];
    [lineImageView release];
    
    UIImageView *lineImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 239, 320, 1)];
    lineImageView2.backgroundColor = [UIColor clearColor];
    [lineImageView2 setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self.contentView addSubview:lineImageView2];
    [lineImageView2 release];
}



- (void) setUpShopModeView
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
//    UILabel *t = [[UILabel alloc] initWithFrame:CGRectMake(14, 15, 60, 16)];
//    t.font = [UIFont fontWithName:kFontNameHeiti size:16];
//    t.textColor = [UIColor colorWithHex:0xff505050];
//    t.text = @"附近";
//    [t setBackgroundColor:[UIColor clearColor]];
//    [self addSubview:t];
//    [t release];
    
    for (int i = 0; i < 5; i++) {
        int row = i/3;
        int number = i%3;
        UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"img_Server_icon%d",i+1]];
        
        UIButton *t = [[UIButton alloc] initWithFrame:CGRectMake(44+96*number, 15+row * 87, 41, 35)];
        [t setImage:img forState:UIControlStateNormal];
        [t setImage:img forState:UIControlStateHighlighted];
        t.tag = i;
        [t addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [t setBackgroundColor:[UIColor clearColor]];
        [self.contentView addSubview:t];
        [t release];
        
        UILabel *tLabel = [[UILabel alloc] initWithFrame:CGRectMake(t.frame.origin.x-10, t.frame.origin.y + t.frame.size.height+11, t.frame.size.width+20, 12)];
        [self.contentView addSubview:tLabel];
        if (i == 0)         tLabel.text = @"店铺管理";
        else if (i == 1)    tLabel.text = @"活动管理";
        else if (i == 2)    tLabel.text = @"印象管理";
        else if (i == 3)    tLabel.text = @"评价管理";
        else if (i == 4)    tLabel.text = @"订单管理";

        tLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
        tLabel.textColor = [UIColor colorWithHex:0xff786e67];
        [tLabel setBackgroundColor:[UIColor clearColor]];
        [tLabel setTextAlignment:NSTextAlignmentCenter];
        [tLabel release];
    }
    UIImageView *lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 88, 320, 1)];
    lineImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
    [lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self.contentView addSubview:lineImageView];
    [lineImageView release];
    
    UIImageView *lineImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 175, 320, 1)];
    lineImageView2.backgroundColor = [UIColor clearColor];
    [lineImageView2 setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self.contentView addSubview:lineImageView2];
    [lineImageView2 release];
}

- (void) buttonClick:(id) sender
{
    UIButton *btn = sender;
    if ([_delegate respondsToSelector:@selector(didClickType:withTitle:)]) {
        NSString *title = nil;
        if (btn.tag == 0)         title = @"美食";
        else if (btn.tag == 1)    title = @"旅游酒店";
        else if (btn.tag == 2)    title = @"火车票";
        else if (btn.tag == 3)    title = @"周边景点";
        else if (btn.tag == 4)    title = @"休闲娱乐";
        else if (btn.tag == 5)    title = @"购物";
        else if (btn.tag == 6)    title = @"商务助理";
        else if (btn.tag == 7)    title = @"积分商城";
        
        [_delegate didClickType:btn.tag withTitle:title];
    }
    
}
@end


@implementation MainPageNormalCell

- (id) initWithTitle:(NSString *)title subTitle:(NSString *)subTitle
{
    self = [super init];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
//        self.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]]];
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        self.contentView.layer.contents = (id)bgImage.CGImage;

        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 11, 80, 18)];
        titleLabel.textColor = [UIColor colorWithHex:0xff505050];
//        titleLabel.font = [UIFont fontWithName:kFontNameHelvetica size:18];
        titleLabel.font = [UIFont systemFontOfSize:18];

        titleLabel.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:titleLabel];
        titleLabel.text = title;
        [titleLabel release];
        
        
        UILabel *subTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 40, 280, 14)];
        subTitleLabel.backgroundColor = [UIColor clearColor];
        subTitleLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
        subTitleLabel.textColor = [UIColor colorWithHex:0xff786e67];
        subTitleLabel.text = subTitle;
        [self.contentView addSubview:subTitleLabel];
        [subTitleLabel release];
        
        UIImageView *lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 71, 320, 1)];
        lineImageView.backgroundColor = [UIColor clearColor];
        NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
        [lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
        [self.contentView addSubview:lineImageView];
        [lineImageView release];
        
    }
    return self;
}

@end
